package ru.maksb.exchange.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;
import java.util.concurrent.BlockingQueue;

public class SystemInHandler implements Runnable {
	private ObjectOutputStream out;
	private BlockingQueue<String> messages;
	
	public SystemInHandler(BlockingQueue<String> messages, ObjectOutputStream out) {
		this.out = out;
		this.messages = messages;
	}

	public void run() {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String message = null;
		try {
			do {
				System.out.println("try to get message from sysin");
				message = reader.readLine();
				System.out.println("try to put message");
				messages.offer(message);
			} while (!"bye".equals(message));
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
